<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>汉诺塔问题</title>
  </head>
  <body>
    <script>
      // 时间复杂度 O(2^n)
      function hanoi(n, a, b, c) {
        if (n > 0) {
          hanoi(n - 1, a, c, b);
          console.log(`把当前错位中最大的从${a}移到${c}`); //此处的a和c是最外层函数的a和c
          hanoi(n - 1, b, a, c);
        }
      }
      hanoi(3, "a", "b", "c");
    </script>
  </body>
</html>
